﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 人事工资管理系统
{
    public partial class frmAddEmployee : Form
    {
        public frmAddEmployee()
        {
            InitializeComponent();
        }
        PMSClass.DBOperate operate = new PMSClass.DBOperate();
        OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
        private void frmAddEmployee_Load(object sender, EventArgs e)
        {
            try
            {
                operate.BindDropdownlist("tb_department", cbbYGBumen, 1);
                cbbYGHunyin.SelectedIndex = 0;
                cbbYGSex.SelectedIndex = 0;
                cbbYGBumen.SelectedIndex = 0;
                txtYGminzu.SelectedIndex = 0;
                string strg = Application.StartupPath.ToString();
                strg = strg.Substring(0,strg.LastIndexOf("\\"));
                strg = strg.Substring(0, strg.LastIndexOf("\\"));
                strg += @"\PMSImage";
                strg += @"\default.jpg";
                OpenFileDialog1.FileName=strg;
                operate.BindDropdownlist("tb_userJob", txtYGZhiwu, 1);

           }
            catch(Exception ex)
                {
                MessageBox.Show(ex.Message);
                }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                operate.Read_Image(OpenFileDialog1, pictureBox1);
            }
            catch (Exception)
            {
                
                MessageBox.Show("加载图片出错");
            }
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            
        }

        private void txtYGNum_TextChanged(object sender, EventArgs e)
        {
            string str = "select count(*) from tb_employee where employeeID='" + this.txtYGNum.Text.Trim() + "'";
            int m = operate.HumanNum(str);
            if (m > 0)
            {
                MessageBox.Show("员工编号已经存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private void txtYGPay_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != 8 && !char.IsDigit(e.KeyChar))
            {
                MessageBox.Show("只能输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Handled = true;
            }
        }

        private void txtYGNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != 8 && !char.IsDigit(e.KeyChar))
            {
                MessageBox.Show("只能输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Handled = true;
            }
        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            if (txtYGBirthday.Text.Trim() == "" || txtYGJiuzhi.Text.Trim() == "" ||
                txtYGminzu.Text.Trim() == "" || txtYGName.Text.Trim() == "" ||
                txtYGNum.Text.Trim() == "" || txtYGPay.Text.Trim() == "" ||
                txtYGPhone.Text.Trim() == "" || txtYGZhiwu.Text.Trim() == "")
            {
                MessageBox.Show("请将信息填写完整", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                if (txtYGPhone.Text.Length != 11)
                {
                    MessageBox.Show("手机号码为11位");
                    return;
                }
                else
                {
                    string str = "select count(*) from tb_employee where employeeID='" + txtYGNum.Text + "'";
                    int i = operate.HumanNum(str);
                    if (i > 0)
                    {
                        MessageBox.Show("该员工编号已经存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else
                    {
                        string strSql = "insert into tb_employee(employeeID,employeeName,employeeSex,employeeDept,employeeBirthday,employeeNation,employeeMarriage,employeeDuty,employeePhone,employeeAccession,employeePay)values('" + txtYGNum.Text.Trim() + "','" + txtYGName.Text.Trim() + "','" + cbbYGSex.Text + "','" + cbbYGBumen.Text + "','" + txtYGBirthday.Text + "','" + txtYGminzu.Text.Trim() + "','" + cbbYGHunyin.Text + "','" + txtYGZhiwu.Text.Trim() + "','" + txtYGPhone.Text.Trim() + "','" + txtYGJiuzhi.Text + "','" + txtYGPay.Text.Trim() + "')";
                        int num = operate.OperateData(strSql);
                        operate.SaveImage(this.txtYGNum.Text.Trim(), OpenFileDialog1);
                        if (num > 0)
                        {
                            MessageBox.Show("员工信息添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }

        private void toolStripLabel2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

       

       
    }
}
